package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/13 09:58
 **/
public class Day11_2_Num647_CountSubstrings {
    class Solution {
        public int countSubstrings(String s) {
            int res = 0;
            char[] arr = s.toCharArray();
            for(int i = 0; i < arr.length; ++i){
                res += find(arr, i, i, arr.length-1);
                res += find(arr, i, i+1, arr.length-1);
            }
            return res;
        }
        private int find(char[] arr, int i, int j, int n){
            int count = 0;
            while(i >= 0 && j <= n && arr[i] ==  arr[j]){
                count++;
                i--;
                j++;
            }
            return count;
        }
    }
}